package models

import (
	"github.com/astaxie/beego/orm"
	"github.com/astaxie/beego"
	"shopping/helper"
)

type Order struct{
	Id          int
	Uid         int
	Totalprice  float64 `orm:"digits(8);decimals(2)"`
	Remarks     string
}

func (n *Order) Addorder(ids []string,uid int,remarks string, totalp float64)(string){
	o := orm.NewOrm()
	var order Order
	order.Uid = uid
	order.Totalprice = totalp
	order.Remarks = remarks
	beego.Debug("Addorder","143")
	//var idsarry = strings.Split(ids, ",")
	//var aaa string
	var str ="UPDATE Item SET flag = 2,oid=? WHERE Id in (0";
	for _, v := range ids {
		str=str+","+v
	}
	str = str +")"
	//beego.Debug("Addorder",ids[0])
	id, err := o.Insert(&order)
	if err == nil{
		res, errrow := o.Raw(str, id).Exec()
		//res, err := o.Raw("UPDATE user SET name = ?", "your").Exec()
		if errrow == nil {
			num, _ := res.RowsAffected()
			return helper.I64ts(num)+"更新数据成功"
		}
		return "更新数据失败"
	}
	return "更新数据失败"

}
